from os import path, getcwd
from yaml import load, FullLoader


class DataLoader:
    """加载yaml文件中的接口信息。"""

    def __init__(self, file: str) -> None:
        directory = file[: file.index("_")]
        # 获取当前文件所在的目录
        with open(
            path.join(
                path.join(path.join(getcwd(), "src"), "data"),
                path.join(directory, file),
            ),
            "r",
            encoding="utf-8",
        ) as f:
            self.data = load(stream=f, Loader=FullLoader)

    def load(self, interface: str) -> dict:
        return self.data[interface]
